import pymysql


def main():
    conn = pymysql.connect(host='192.168.3.11', port=3306, user='root', password='123', db='hrs', charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute('select dno,dname,dloc from tb_dept;')
            for i in cursor.fetchall():
                print('部门编号：',i[0])
                print('部门名称:',i[1])
                print('部门所在地',i[2])
                print('_____________')
    except pymysql.MySQLError as error:
        print(error,'查询失败')
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
